<?php /*a:3:{s:48:"E:\phpthink\work\tp\view\home\lending\index.html";i:1653031018;s:19:"common2/header.html";i:1653031360;s:19:"common2/footer.html";i:1652023572;}*/ ?>


<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>图书馆管理系统</title>
  <!-- 引入 layui.css -->
  <link rel="stylesheet" href="http://127.0.0.1:8000/layui/css/layui.css">
  <link rel="stylesheet" href="http://127.0.0.1:8000/layer/layer.js">
  <!-- 引入 layui.js -->
  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  <link rel="stylesheet" href="http://127.0.0.1:8000/static/index.css">
  <script src="http://127.0.0.1:8000/layui/layui.js"></script>
  <link href="http://127.0.0.1:8000/bootstrap-3.4.1-dist/css/bootstrap.css" rel="stylesheet">
  <script src="http://127.0.0.1:8000/jquery-3.6.0.min.js"></script>
  <script src="http://127.0.0.1:8000/bootstrap-3.4.1-dist/js/bootstrap.js"></script>
  <script src="http://127.0.0.1:8000/echarts.min.js"></script>
</head>
<body>
<div class="layui-layout layui-layout-admin">
  <div class="layui-header">
    <div class="layui-logo layui-hide-xs layui-bg-black">图书管理系统</div>
    <ul class="layui-nav layui-layout-right">
      <li class="layui-nav-item"><a href="#"><?php echo session("username"); ?>&nbsp;已登录</a></li>
      <li class="layui-nav-item layui-hide layui-show-md-inline-block">
        <a href="javascript:;">
          更多操作
        </a>
        <dl class="layui-nav-child">
          <dd><a href="/signOut">退出登录</a></dd>
        </dl>
      </li>
    </ul>
  </div>

  <div class="layui-side layui-bg-black">
    <div class="layui-side-scroll">
      <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
      <ul class="layui-nav layui-nav-tree" lay-filter="test">
        <li class="layui-nav-item layui-nav-itemed">
          <a class="" href="javascript:;">图书展示</a>
          <dl class="layui-nav-child">
            <dd><a href="/home/booklist">图书列表</a></dd>
          </dl>
        </li>
        <li class="layui-nav-item">
          <a href="javascript:;">借阅管理</a>
          <dl class="layui-nav-child">
            <dd><a href="/home/Lending">借阅列表</a></dd>
          </dl>
        </li>
        <li class="layui-nav-item">
          <a href="javascript:;">个人中心</a>
          <dl class="layui-nav-child">
            <dd><a href="/home/lendinghistory">历史借阅</a></dd>
            <dd><a href="/home/personal">个人中心</a></dd>
          </dl>
        </li>
      </ul>
    </div>
  </div>
<!-- 内容主体区域 -->
<div class="layui-body">
    <!--        <div style="padding: 15px;"><h1 style="font-weight: 700">欢迎界面</h1></div>-->
    <div id="user_container" style="padding: 15px;">
        <!--            面包屑导航-->
        <span class="layui-breadcrumb">
              <a href="#" style="font-weight: 700;color: #000!important;">首页</a>
              <a href="#" style="font-weight: 700;color: #000!important;">图书展示</a>
              <a href="" >图书列表</a>
            </span>
        <div class="layui-row layui-col-space15" style="margin-top: 15px">
            <div class="layui-col-md12">
                <div class="layui-panel" style="padding: 20px">
                    <div class="layui-form-item">

                    </div>
                    <table lay-filter="adminTable"  class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</div>



<!--操作模板字符-->
<script type="text/html" id="currentTableBar">
    <a  class="layui-btn layui-btn-warm layui-btn-sm data-count-edit" lay-event="edit">点击还书</a>
</script>



<script>
    document.querySelector('.layui-nav-itemed').classList.remove('layui-nav-itemed');
    $('a[href$=Lending]').parent()[0].classList.add('layui-this');
    $('a[href$=Lending]').parent().parent().parent()[0].classList.add('layui-nav-itemed');

    var formhorizontal  = document.querySelector('.form-horizontal')
    var sureBtn = document.getElementById('sureBtn');
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;







        // 渲染表格
        table.render({
            elem: '#currentTableId',
            limit:4
            ,url: "<?php echo url('/home/Lending/article'); ?>" //数据接口
            ,page: true //开启分页
            ,limits:[2,4,6,8]
            ,skin: 'row,line'
            ,id:'bookTable'
            ,cols: [[ //表头
                // {type: "checkbox", },
                {field: 'id',align:"center", width: 80, title: '编号', sort: true},
                {field: 'bname',align:"center", title: '名称'},
                {field: 'should_return_date',align:"center", title: '是否超时',templet:function (d) {
                    // console.log(d)
                    if(d.should_return_date<((new Date()).valueOf()))
                        return '是';
                    else return '否';

                    }},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],

        });




        function toNextTimes(n){
            let timestamp = +new Date() + n * 86400000;
            return timestamp;
        }


        // 编辑删除绑定事件
        table.on('tool(adminTable)', async function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
            var a=0;
            var t=0;
            if(layEvent === 'edit'){

                console.log(data.lending_date)
                if(data.should_return_date<((new Date()).valueOf())){
                    a = Math.floor((-data.should_return_date + ((new Date().valueOf())))/86400000);
                }
                t=a*5;
                layer.confirm(`当前已超时${a}天,需交纳${t}元`,{icon: 6, title:'还书提示'}, async function(index){
                    const {data:res} = await axios.post('/home/lending/returnBook',{
                        book_id:data.id,
                        lending_date:data.lending_date,
                        return_at:(new Date()).valueOf(),
                        money_fine:parseInt(t)
                    })
                    console.log(res)
                    table.reload('bookTable', {});
                    layer.msg('还书成功', {
                        icon: 1,
                        time: 1500
                    })
                    layer.close(index);
                    //向服务端发送删除指令
                });
            }

        });

    });




</script>



</body>

</html>
